package com.itheima.d2_list;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;

/**
 * List集合
 * 掌握List集合的特有方法  索引相关
 */
public class ListDemo1 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        //添加元素
        list.add("宁姚");
        list.add("阮秀");
        list.add("李宝瓶");
        list.add("贺小凉");
        list.add("王朱");
        System.out.println(list);

        //特有添加方法
        list.add(1,"有村架纯");
        System.out.println(list);

        list.remove(5);
        System.out.println(list);

        //特有的修改方法
        System.out.println(list.set(4, "黎若雨"));
        System.out.println(list);

        System.out.println(list.get(1));

        System.out.println("======================");

        //for循环 索引
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        System.out.println("======================");

        //迭代器
        Iterator<String> it = list.iterator();
        while(it.hasNext()){
            String str = it.next();
            System.out.println(str);
        }
        System.out.println("======================");

        //增强for
        for (String s : list) {
            System.out.println(s);
        }
        System.out.println("======================");

        //foreach lambda表达式
        list.forEach(s ->System.out.println(s));
        System.out.println("======================");

        //方法引用
        list.forEach(System.out::println);


    }
}
